Hi all, I am trying to convert my data from long format to wide. Each patient (ID), has multiple ECGs, multiple echocardiograms and pacemaker checks at different times points. Below is a simplified version of my database. DIAGNOSISDATE, is when a patient (ID) was diagnosed with heart disease. Then had multiple tests done during follow up. I have the DATE of each test, time from diagnosis for each test (in days) and a variable attributable to each test. For instance, for each ECHODATE I measured patients heart volume, and for each PACEMAKER check date I recorded whether it was abnormal or not, etc. Now all these time varying variables have different dates. I assume the value for my measurements does not change in between my measurements so I should be able to carry forward prior observations. I thought if I create a variable that would include ALL PROCEDURE DATES (ECG, ECHO, PACEMAKER), then I can sort by ID and for every mission row carry forward the prior observation for each variable, but I cannot seem to find a way to do that. Is there a better way to do this before reshaping the data from Long to Wide? Sorry if this is a very basic question. Thank you for your help.
ID | DIAGNOSISDATE | ECHODATE_Dx | ECHODATE | HEARTVOL | PACEDATE_Dx | PACEDATE | ABNLPACE | ECGDATE-dx | ECGDATE | ABNLECG | |
2 | 4/27/09 | 4 | 5/1/09 | 22.46 | 1289 | 11/6/12 | 0.00 | 24.00 | 5/21/2009 | 1 | |
2 | 4/27/09 | 1289 | 11/6/12 | 25.46 | 1456 | 4/22/13 | 1.00 | 441.00 | 7/12/2010 | 1 | |
2 | 4/27/09 | 2065 | 12/22/14 | 26.82 | 2065 | 12/22/14 | 1.00 | 756.00 | 5/23/2011 | 1 | |
2 | 4/27/09 | 2464 | 1/25/16 | 27.66 | 3059 | 9/11/17 | 1.00 | 1289.00 | 11/6/2012 | 1 | |
2 | 4/27/09 | 3213 | 2/12/18 | 28.83 | 3213 | 2/12/18 | 0.00 | 1456.00 | 4/22/2013 | 1 | |
2 | 4/27/09 | 3724 | 7/8/19 | 27.00 | 3724 | 7/8/19 | 0.00 | 2065.00 | 12/22/2014 | 1 | |
2 | 4/27/09 | 2464.00 | 1/25/2016 | 1 | |||||||
2 | 4/27/09 | 2527.00 | 3/28/2016 | 1 | |||||||
2 | 4/27/09 | 3059.00 | 9/11/2017 | 1 | |||||||
2 | 4/27/09 | 3216.00 | 2/15/2018 | 1 | |||||||
2 | 4/27/09 | 3724.00 | 7/8/2019 | 1 | |||||||
1 | 1/8/07 | 21 | 1/29/07 | 18.89 | 1764 | 11/7/11 | 0.00 | 217.00 | 8/13/07 | 1 | |
1 | 1/8/07 | 1291 | 7/22/10 | 19.25 | 1852 | 2/3/12 | 0.00 | 469.00 | 4/21/08 | 1 | |
1 | 1/8/07 | 1680 | 8/15/11 | 23.34 | 2072 | 9/10/12 | 0.00 | 903.00 | 6/29/09 | 1 | |
1 | 1/8/07 | 2111 | 10/19/12 | 22.13 | 2086 | 9/24/12 | 0.00 | 1107.00 | 1/19/10 | 1 | |
1 | 1/8/07 | 2283 | 4/9/13 | 21.15 | 2111 | 10/19/12 | 0.00 | 1568.00 | 4/25/11 | 1 | |
1 | 1/8/07 | 3003 | 3/30/15 | 23.41 | 2123 | 10/31/12 | 0.00 | 2122.00 | 10/30/12 | 1 | |
1 | 1/8/07 | 3934 | 10/16/17 | 19.50 | 2254 | 3/11/13 | 0.00 | 2312.00 | 5/8/13 | 1 | |
1 | 1/8/07 | 2282 | 4/8/13 | 12.00 | 3003.00 | 3/30/15 | 1 | ||||
1 | 1/8/07 | 2312 | 5/8/13 | 0.00 | 3934.00 | 10/16/17 | 1 | ||||
1 | 1/8/07 | 2327 | 5/23/13 | 0.00 | |||||||
1 | 1/8/07 | 2416 | 8/20/13 | 0.00 | |||||||
1 | 1/8/07 | 3934 | 10/16/17 | 0.00 |
Comment